//========================================================================
//  This software is free: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License Version 3,
//  as published by the Free Software Foundation.
//
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  Version 3 in the file COPYING that came with this distribution.
//  If not, see <http://www.gnu.org/licenses/>.
//========================================================================
/*!
\file    skeleton_pointing.h
\brief   C++ Interface: SkeletonPointing
\author  Joydeep Biswas, (C) 2011
*/
//========================================================================

#include "stdio.h"
#include <math.h>
#include <QtGui/QApplication>
#include <QObject>
#include <QThread>
#include <QPointF>
#include <QLineF>
#include <QVector>
#include <QMutex>
#include <QUdpSocket>
#include "gui.h"
#include "kinect_wrapper.h"
#include "pointing_engine.h"

#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
//void Sleep(double sec){ Sleep(DWORD(sec*1000));}
//double GetTimeSec(){ return double(GetTickCount())/1000.0; }
#else
#include "timer.h"
#endif

#ifndef SKELETON_POINTING_H
#define SKELETON_POINTING_H

bool runApp = true;
bool testMode = false;
SkeletonPointingGUI* display;
QApplication* app;


class SkeletonPointing : public QThread
{ 
  KinectWrapper kinect;
  PointingEngine pointingEngine;
  bool calibrationComplete[3];
  double conditionNumbers[3];
  vector3d calibrationPoints[4];
  QMutex pointingEngineMutex;
  QUdpSocket* net;
  vector2d target;
  vector3d target3d;
  
private:
  void testDisplay();
  void publishData();
  
protected:
  void run();

public:
  SkeletonPointing(QObject* parent = 0){}
  ~SkeletonPointing(){}
  void statusCallback(void* data);
  void checkCalibration();
  void labeledDepthImageUpdate(BYTE* img);
  void rgbImageUpdate(BYTE* img);
  void skeletonUpdate(NUI_SKELETON_FRAME* data);
  void startCalibration(int pointNum);
  void stopCalibration();
  void calibrationLoadSave(bool load);
};

#endif //SKELETON_POINTING_H